package com.example.new5.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.example.new5.R;
import com.example.new5.entity.Olympic;

import java.util.List;

public class OlympicAdapter extends RecyclerView.Adapter<OlympicAdapter.OlympicViewHolder> {
    private List<Olympic> olympicList;

    public OlympicAdapter(List<Olympic> medalDataList) {
        this.olympicList = medalDataList;
    }

    @Override
    public OlympicViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_olympic, parent, false);
        return new OlympicViewHolder(view);
    }

    @Override
    public void onBindViewHolder(OlympicViewHolder holder, int position) {
        Olympic olympic = olympicList.get(position);
        holder.rankTextView.setText(olympic.getRank());
        holder.countryidTextView.setText(olympic.getCountryid());
        holder.countrynameTextView.setText(olympic.getCountryname());
        holder.goldTextView.setText(olympic.getGold());
        holder.silverTextView.setText(olympic.getSilver());
        holder.bronzeTextView.setText(olympic.getBronze());
        holder.countTextView.setText(olympic.getCount());
    }
    @Override
    public int getItemCount() {
        return olympicList.size();
    }

    class OlympicViewHolder extends RecyclerView.ViewHolder {
        TextView rankTextView,countryidTextView,countrynameTextView,goldTextView,silverTextView;
        TextView bronzeTextView,countTextView;
        public OlympicViewHolder(View itemView) {
            super(itemView);
            rankTextView = itemView.findViewById(R.id.rank);
            countryidTextView = itemView.findViewById(R.id.countryid);
            countrynameTextView = itemView.findViewById(R.id.countryname);
            goldTextView = itemView.findViewById(R.id.gold);
            silverTextView = itemView.findViewById(R.id.silver);
            bronzeTextView = itemView.findViewById(R.id.bronze);
            countTextView = itemView.findViewById(R.id.count);
        }
    }
}
